#ifndef MAILER_H_
#define MAILER_H_

#include <string>
#include <map>
#include <vector>
#include <algorithm>
#include <queue>
#include <pthread.h>
#include "Node.h"
#include "BoundMailBox.h"
#include "OSThread.h"
#include "Scheduler.h"

using namespace std;

class Mailer{
public:
	Mailer(int buffSize, int numOfNode);
	virtual ~Mailer();
	void createNode(vector<int> v);
	void printGraph();
	void createRTs();
	void printRTs();
	void Recv(/*Message* msg, Node* node*/);
	void run(int algoNum, int quanta);
	void addFirst(Message* msg);
	void addLast(Message* msg);
	void start();
	bool stabilized();
	bool fullInbox();
	pthread_cond_t getShellCondVar();
	pthread_mutex_t getShellMutex();
	pthread_cond_t getMailboxCondVar();
	pthread_mutex_t getMailboxMutex();
	bool emptyInbox();

private:
	BoundMailBox* _mailbox;
	int _numOfNodes;
	//int holding;
	//map<int,UnBoundedMailBox*> _nodesMailboxes; // put in NODE
	map<int,Node*> _nodes;
	vector<int> _nodeIds;
	vector<Node*> _nodesVec;
	Scheduler* _scheduler;
	pthread_t _pThread;
	pthread_cond_t _shellCondVar;
	pthread_mutex_t _shellMutex;
	pthread_cond_t _MailboxCondVar;
	pthread_mutex_t _MailboxMutex;
};
#endif /* MAILER_H_ */
